package top.orange.picacg.model;

import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.LinkTree;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.ViewType;
import xyz.erupt.annotation.sub_field.sub_edit.AttachmentType;
import xyz.erupt.annotation.sub_field.sub_edit.ChoiceType;
import xyz.erupt.annotation.sub_field.sub_edit.HtmlEditorType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.upms.handler.SqlChoiceFetchHandler;
import xyz.erupt.upms.model.base.HyperModel;

import javax.persistence.*;

/**
 * @author dell
 */

@Erupt(
        name = "图片表",
        power = @Power(importable = true, export = true),
        linkTree = @LinkTree(field = "typeName")
)
@Table(name = "p_picture")
@Entity
public class PictureModel extends HyperModel {

    @EruptField(
            views = @View(title = "用户名称", width = "75px"),
            edit = @Edit(
                    title = "用户名称",
                    notNull = true, search = @Search,
                    type = EditType.CHOICE,
                    choiceType = @ChoiceType(
                            fetchHandler = SqlChoiceFetchHandler.class,
                            fetchHandlerParams = {"select name from p_user","3000"}
                    )
            )
    )
    private String userName;

    @ManyToOne
    @EruptField(
            views = @View(title = "类型名称", width = "75px", column = "name"),
            edit = @Edit(
                    title = "类型名称",
                    notNull = true, search = @Search,
                    type = EditType.REFERENCE_TREE
            )
    )
    private TypeModel typeName;

    @EruptField(
            views = @View(title = "图片", width = "150px"),
            edit = @Edit(title = "图片", type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType(type = AttachmentType.Type.IMAGE, maxLimit = 3))
    )
    private String pic;

    @EruptField(
            views = @View(title = "标题", width = "100px"),
            edit = @Edit(title = "标题", notNull = true, search = @Search(vague = true))
    )
    private String title;

    @Lob
    @EruptField(
            views = @View(title = "介绍", type = ViewType.HTML),
            edit = @Edit(title = "介绍", type = EditType.HTML_EDITOR,
                    htmlEditorType = @HtmlEditorType(HtmlEditorType.Type.CKEDITOR))
    )
    private String content;

    @Lob
    @EruptField(
            views = @View(title = "备注", width = "75px"),
            edit = @Edit(title = "备注", type = EditType.TEXTAREA)
    )
    private String remark;

}
